package com.hwh.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hwh.service.Admin1Service;
import com.hwh.serviceIm.SeviceImpl;
import com.hwh.vo.Admin1;

public class ALoginController extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
	         throws ServletException, IOException {
        super.doPost(req, resp);
    }

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		// 获取前台form表单的input输入框
		String a_name = req.getParameter("a_name");
		String a_psw = req.getParameter("a_psw");
		Admin1 ad = new Admin1();
		ad.setA_name(a_name);
		ad.setA_pwd(a_psw);
		Admin1Service vds = new SeviceImpl();
		Admin1 a = vds.ValiAdmin1(ad);
		HttpSession session = req.getSession();
		session.setAttribute("Admin1", a);
		
		if (a.getA_name() != null) {
			// 返回的不是空值,重定向到登录成功界面
			
			req.getRequestDispatcher("aindex.jsp").forward(req, resp);
		} else {
			
			req.getRequestDispatcher("alogin.jsp").forward(req, resp);
		}
	}

}
